package com.idea.boot.controller;

import com.idea.boot.entity.User;
import com.idea.boot.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Slf4j
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        System.out.println("hello 5555555");
        log.debug("hello to myself");
        return "Hello SpringBoot!";
    }

    @RequestMapping("/getLoginPage")
    public String getLoginPage(){
        log.debug("This is a login test!!!");
        return "login";
    }

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<User> selectAll(){
        List<User> list = userMapper.selectAll();
        return list;
    }

    @RequestMapping("/getUserListPage")
    public String getUserListPage(Model model){
        List<User> list = userMapper.selectAll();
        model.addAttribute("list", list);

        return "user_list";
    }
}
